<?php
/**
 * Created by PhpStorm.
 * User: shx
 * Date: 2016/11/28
 * Time: 17:45
 */

namespace App\Models\Live;

trait LiveStream
{
    public function getLiveStreamAttribute()
    {
        //斗鱼
        if ($this->live_id === 2) {
            return
                <<<STREAM
                    <embed width="1120" height="630" allownetworking="all" allowscriptaccess="always" 
    src="http://staticlive.douyucdn.cn/common/share/play.swf?room_id={$this->room_id}" 
    quality="high" bgcolor="#000" wmode="window" allowfullscreen="true" 
    allowFullScreenInteractive="true" type="application/x-shockwave-flash">
STREAM;
        }

        //战旗
        if ($this->live_id === 4) {
            return
                <<<STREAM
                <iframe src="http://www.zhanqi.tv/live/embed?roomId={$this->room_id}" width="100%" height="100%"  frameborder="0"></iframe>
STREAM;
        }
        //龙珠
        if ($this->live_id === 5) {
            return
                <<<STREAM
                <iframe src="http://longzhu.com/static/topic/a20160105u9.html?roomid={$this->room_id}" width="100%" height="100%"  frameborder="0"></iframe>
STREAM;
        }

        //全民
        if ($this->live_id === 3) {
            return
                <<<STREAM
                <iframe width="100%" height="100%" src="http://www.quanmin.tv/embed/{$this->room_id}" name="iframe" allowtransparency="true" frameborder="0" scrolling="no"></iframe>
STREAM;
        }

        //熊猫
        if ($this->live_id === 1) {
            return $this->getPandaLs();
        }

        //虎牙
        if ($this->live_id == 6) {
            return $this->getHuyaLs();
        }

        //6room
        if ($this->live_id == 12) {
            return $this->get6Ls();
        }

        //繁星
        if ($this->live_id == 7) {
            $id = [];
            preg_match('/\d+/', $this->id, $id);
            return
                <<<STREAM
    <object type="application/x-shockwave-flash" id="liveFlashBox" width="1120px" height="630px" data="http://image.fanxing.kugou.com/staticPub/node_modules/fx.live/swf/PlayPlayer_139e2eb.swf">
<param name="scale" value="noScale">
<param name="wmode" value="transparent">
<param name="allowScriptAccess" value="always">
<param name="allowFullscreen" value="true">
<param name="flashvars" value="liveName=fx_hifi_{$id[0]}&liveStatus=1">
</object>
STREAM;
        }

        if ($this->live_id == 9) {
            return $this->getHuajiaoLs();
        }

        //bilibili
        if ($this->live_id == 10) {
            return <<<STREAM
<embed wmode="opaque" src="http://static.hdslb.com/live-static/swf/LivePlayerEx_1.swf?room_id={$this->room_id}&cid={$this->room_id}&state=LIVE" quality="high" width="100%" height="100%"  align="middle" allowScriptAccess="always" allowFullScreen="true" mode="transparent" type="application/x-shockwave-flash"></embed>
STREAM;
        }

        //cc
        if ($this->live_id == 11) {
            return <<<STREAM
<embed wmode="opaque" src="http://service.hi.163.com/static/v/CCMediaPlayer.swf?v=0.3.9&geturl=1&maskinterval=30&secret=None&defaultip=114.113.200.201&file={$this->room_id}&provider=rhttp&debug=true&groupcgihost=group.v.cc.163.com&autoplay=true" quality="high" width="100%" height="100%"  align="middle" allowScriptAccess="always" allowFullScreen="true" mode="transparent" type="application/x-shockwave-flash"></embed>
STREAM;
        }

        //触手
        if ($this->live_id == 13) {
            return <<<STREAM
            <embed src="http://kascdn.kascend.com/jellyfish/open/chushou_tv_player_v4.swf?roomId={$this->room_id}&source=1102&getDomain=http%3A%2F%2Fchushou.tv" quality="high" wmode="opaque" width="100%" height="100%"  align="middle" allowScriptAccess="always" allowFullScreen="true" mode="transparent" type="application/x-shockwave-flash"></embed>
STREAM;
        }

        //一直播
        if ($this->live_id == 14) {
            return '<iframe src="http://static.yizhibo.com/pc_live/static/video.swf?scid='.$this->room_id.'" width="100%" height="100%"  frameborder="0"></iframe>';
        }

        //yy
        if ($this->live_id == 15) {
            return '<embed width="100%" height="100%" allownetworking="all" allowscriptaccess="always" src="http://weblbs.yystatic.com/s/'.$this->room_id.'/'.$this->room_id.'/huyacoop.swf" quality="high" bgcolor="#000" wmode="window" allowfullscreen="true" allowFullScreenInteractive="true" type="application/x-shockwave-flash">';
        }

        return '';
    }

    private function getPandaLs()
    {
        try {
            $data = file_get_contents("http://www.panda.tv/api_room_v2?roomid={$this->room_id}");
            $data = json_decode($data)->data;

            return <<<STREAM
<iframe src="http://s6.pdim.gs/static/ece0e6c1f95a0bcd.swf?sign=true&roomUrl=http://www.panda.tv/{$this->room_id}&videoId={$data->videoinfo->room_key}&plflag={$data->videoinfo->plflag}&roomId={$this->room_id}" width="100%" height="100%" frameborder="0"></iframe>
STREAM;
        } catch (\Exception $e) {
            return '';
        }

    }

    private function getHuyaLs()
    {
        try {

            $data = file_get_contents($this->url);
            $matchs = [];
            $url = '';
            preg_match('/"chTopId"[":\s]+(\d+)/', $data, $matchs);
            $url .= $matchs[1] . '/';
            preg_match('/"subChId"[":\s]+(\d+)/', $data, $matchs);
            $url .= $matchs[1];

            return <<<STREAM
<embed width="100%" height="100%" allownetworking="all" allowscriptaccess="always" src="http://weblbs.yystatic.com/s/{$url}/huyacoop.swf" quality="high" bgcolor="#000" wmode="window" allowfullscreen="true" allowFullScreenInteractive="true" type="application/x-shockwave-flash">
STREAM;
        } catch (\Exception $e) {
            return '';
        }

    }

    private function getHuajiaoLs()
    {
        try {
            $data = file_get_contents($this->url);
            $matchs = [];
            preg_match('/_LC.+_.?X/', $data, $matchs);
            $sn = $matchs[0];

            return <<<STREAM
<iframe src="http://s3.qhres.com/static/ec04d00f84474a0b.swf?sn={$sn}&liveId={$this->room_id}" width="100%" height="100%" frameborder="0"></iframe>
STREAM;
        } catch (\Exception $e)
        {
            return '';
        }
    }

    private function get6Ls()
    {
        try {
            $data = file_get_contents($this->url);
            $matchs = [];
            preg_match('/"flvtitle":"(v\d+-\d+)",/', $data, $matchs);
            $sn = $matchs[1];

            return <<<STREAM
<iframe src="http://v.6.cn/apple/livePlayer/roomplayer/roomLivePlayer4.4.swf?fileName=$sn" width="100%" height="100%" frameborder="0"></iframe>
STREAM;
        } catch (\Exception $e)
        {
            return '';
        }
    }
}